package com.gxj.study.shopdemo.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gxj.study.shopdemo.LoginActivity;
import com.gxj.study.shopdemo.MyApplication;
import com.gxj.study.shopdemo.bean.User;
import com.lidroid.xutils.ViewUtils;

/**
 * Created by 祥杰 on 2016/8/25.
 */

public abstract class BaseFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = createView(inflater,container,savedInstanceState);
        ViewUtils.inject(this,view);

        initToolBar();
        init();
        return view;
    }

    public void initToolBar() {

    }

    public abstract void init();

    public abstract View createView(LayoutInflater inflater,ViewGroup container,Bundle saveInstanceState);

    public void startActivity(Intent intent,boolean isNeedLogin){
        if (isNeedLogin){
            User user = MyApplication.getInstance().getUser();
            if (user != null){
                super.startActivity(intent);
            }else {
                MyApplication.getInstance().putIntent(intent);
                Intent loginIntent = new Intent(getActivity(),LoginActivity.class);
                super.startActivity(loginIntent);
            }
        }
    }
}
